package com.kc.web.controller.business;

import com.kc.business.domain.BizUserCreation;
import com.kc.business.service.IBizUserCreationService;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.utils.StringUtils;
import com.kc.framework.web.domain.server.Sys;
import com.kc.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 用户创作相关
 */
@RestController
@RequestMapping("/user/creation")
public class BizUserCreationController extends BaseController {
    @Autowired
    private IBizUserCreationService iBizUserCreationService;
    @Autowired
    private ISysDictDataService iSysDictDataService;

    /**
     * 用户创作列表
     * @param bizUserCreation
     * @return
     */
    @PreAuthorize("@ss.hasPermi('user:creation:list')")
    @GetMapping(value = "/getList")
    public TableDataInfo getList(BizUserCreation bizUserCreation){

        startPage();
        List<BizUserCreation> userCreationList = iBizUserCreationService.getList();
        //获取分类名称
        for(BizUserCreation userCreation:userCreationList){
            userCreation.setTypeName(iSysDictDataService.selectDictLabel("user_creation_type",userCreation.getType().toString()));
            userCreation.setImageList(Arrays.asList(StringUtils.split(userCreation.getImage(),",")));
        }
        return getDataTable(userCreationList);
    }

    /**
     * 审核通过
     * @param bizUserCreation
     * @return
     */
    @PreAuthorize("@ss.hasPermi('user:creation:checkPass')")
    @PutMapping(value = "/checkPass")
    public AjaxResult checkPass(@RequestBody  BizUserCreation bizUserCreation){
        if(bizUserCreation.getIsOfficial() == null){
            bizUserCreation.setIsOfficial(0);
        }
        if(bizUserCreation.getStatus().equals("1")) {
            return toAjax(iBizUserCreationService.examinePass(bizUserCreation.getId()));
        }else{
            if(bizUserCreation.getRefuseInfo().equals("") || bizUserCreation.getRefuseInfo() == null){
                AjaxResult.error("参数错误");
                return toAjax(0);
            }
            return toAjax(iBizUserCreationService.examineRefuse(bizUserCreation.getId(),bizUserCreation.getRefuseInfo()));
        }
    }

    /**
     * 审核通过
     * @param bizUserCreation
     * @return
     */
    @PreAuthorize("@ss.hasPermi('user:creation:checkRefuse')")
    @PutMapping(value = "/checkRefuse")
    public AjaxResult checkRefuse(@RequestBody  BizUserCreation bizUserCreation){
        if(bizUserCreation.getRefuseInfo().equals("") || bizUserCreation.getRefuseInfo() == null){
            AjaxResult.error("参数错误");
            return toAjax(0);
        }
        return toAjax(iBizUserCreationService.examineRefuse(bizUserCreation.getId(),bizUserCreation.getRefuseInfo()));
    }
}
